<?php

namespace App\Providers;

use App\Exceptions\DingoExceptionHandler;
use Dingo\Api\Exception\Handler;
use Illuminate\Routing\Route;
use Illuminate\Support\ServiceProvider;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('api.exception', function () {
            return new DingoExceptionHandler(
                $this->app['Illuminate\Contracts\Debug\ExceptionHandler'],
                config('api.errorFormat'),
                config('api.debug')
            );
        });
    }

    /**
     * @Notes:定义验证场景
     * @author: Liao Hong
     * @Time: 2025/10/20   11:50
     * @Interface boot
     */
    public function boot(): void
    {
        Route::macro('scene', function ($scene=null) {
            $action = Route::getAction();
            $action['_scene'] = $scene;
            Route::setAction($action);
        });
    }
}
